import time
import tkinter as tk


class cannonBall:

    def __init__(self,base_window,x,y,direction):
        self.cannon_ball_label = None
        self.base_window=base_window
        self.x=x
        self.y=y
        self.direction=direction
        self.create_connon_ball()


    def create_connon_ball(self):
        self.cannon_ball_label = tk.Label(self.base_window, background="red")
        self.cannon_ball_label.place(x=self.x, y=self.y, width=30, height=30)


    def update_connon_ball_position(self):
        # 更新Label的位置
        self.cannon_ball_label.place(x=self.x, y=self.y, width=30, height=30)
        # 每隔50毫秒调用一次这个函数
        self.x -= 1
        self.y -= 1
        if 0 < self.x < 1080 and 0 < self.y < 720:
            self.base_window.after(10, self.update_connon_ball_position)
        else:
            print("销毁炮弹..")
            self.cannon_ball_label.destroy()


